<?php

$SCRIPTS .= "
<script type=text/javascript>
    function afterLoad() {
        var ta = document.getElementsByTagName('textarea')[0];
        ta.value = ta.value.replace(/<br>/g, \"\\n\");
    }
    window.onload = window.setTimeout(afterLoad, 500);
</script>";

$t_data = array(
    "link"  => stripslashes(trim($_POST["link"])),
    "title" => stripslashes(trim($_POST["title"])),
    "text"  => htmlspecialchars_decode(str_replace("\n", "{EOF}", $_POST["text"]), ENT_QUOTES));

if ($_POST["check_yes"] != "yes") {
    $t_tpl = GetTpl("addpage");
    $PagesList = GetPagesList($GL);
    $t_replace = array(
        "{link}" => $t_data["link"],
        "{title}" => $t_data["title"],
        "{text}" => htmlspecialchars($t_data["text"], ENT_QUOTES),
        "{pages}" => $PagesList);
    foreach ($t_replace as $k => $v)
        $t_tpl = str_replace($k, $v, $t_tpl);

    $t_title = "Добавить страницу";
    $HEADER .=" - ".$t_title;
    $t_BODY = $t_tpl;
}
else{
    $t_data["text"] = str_replace("\n", "{EOF}", htmlspecialchars($_POST["text"], ENT_QUOTES));
    if (preg_match("/^[a-zA-Z0-9_-]{1,10}$/", $t_data["link"]) and AddPage($GL, $t_data)) {
        Logger($LogFile, "ADMIN ADD PAGE (http://" . $SITE . "/?action=" . $t_data["link"] . ")");
        header("Location: http://" . $SITE . "/?action=" . $t_data["link"]);
    }
    else {
        header("Location: http://" . $SITE . "/?action=error");
    }
}

?>
